package com.scenic.rd_android.basic_knowledge;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.nova.scenic.projectlibs.util.debug.MyLog;
import com.scenic.rd_android.R;

public class TestSQLite extends AppCompatActivity {

    static MyLog log = new MyLog("TestSQLite");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_sqlite);
        SQLiteDatabase db = new MySQLite(getApplicationContext(), "Test_DB", 1).getWritableDatabase();

        log.debug("aaaaaaaaaaaaaa");
        log.info("aaaaaaaaaaaaaa");
        log.error("aaaaaaaaaaaaaa");
    }



    public static class MySQLite extends SQLiteOpenHelper {

        public MySQLite(Context context, String name, int version) {
            super(context, name, null, version);
        }

        public MySQLite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
            super(context, name, factory, version, errorHandler);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            log.debug("DB onCreate ");
            String sql =
                    "create table if not exists Test(" +
                            "id primary key auto_increment " +
                            "name varchar(255) " +
                            " age integer " +
                            ")";
            db.execSQL(sql);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        }
    }
}
